package onetotwenty;

import java.util.Arrays;

import org.junit.Test;

//TODO 내가 푼게 아님, 나중에 비슷한 문제가 나올 때, 참고할 수 있도록...
public class ProblemSixteen {
	private static int MAX_LENGTH = 5000;

	@Test
	public void testName() {
		int[] result = new int[MAX_LENGTH];
		Arrays.fill(result, 0);
		int i, j, size = 0, sum = 0;

		result[0] = 1;

		for (i = 0; i < 1000; i++) {
			for (j = 0; j < MAX_LENGTH; j++) {
				result[j] *= 2;
			}

			for (j = 0; j < MAX_LENGTH - 1; j++) {
				while (result[j] >= 100000) {
					result[j] -= 100000;
					result[j + 1]++;
					if (j + 1 > size) {
						size = j + 1;
					}
				}
			}
		}

		for (i = 0; i <= size; i++) {
			sum += result[i] % 10;
			sum += result[i] % 100 / 10;
			sum += result[i] % 1000 / 100;
			sum += result[i] % 10000 / 1000;
			sum += result[i] / 10000;
		}

		for (i = 0; i < size; i++) {
			System.out.println(i + " : " + result[i]);
		}
		System.out.println();

		System.out.println(sum);
	}
}
